<table width="100%" class="cms_browsetext"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <TH width="300">Name</TH>
    <TH >Subscribers</TH>
    <TH width="35">Active</TH>
    <TH>User Management</TH>
    <TH>Actions</TH>
  </TR>
  <?
  $addMode = CMS_ADD_QUICK_ADD_GO;
  $addUrlDict = array(
  		'fileNo'=> SMS_LIST_ADD,
		'formId'=> SMS_LIST_FORM,
  );
  
  $smsListTableWriter = new CmsTableWriter("smslist_list", $db );
  $smsUserListTableWriter = new CmsTableWriter("smslist_listuser", $db );
  $listUsersTableWriter = new CmsTableWriter("smslist_cms_listusers", $db);
  $listGroupsTableWriter = new CmsTableWriter("smslist_cms_listgroups", $db);
  
  $disable = extractBooleanWithKeyFromArray("disable", $_REQUEST, 0);
  $enable = extractBooleanWithKeyFromArray("enable", $_REQUEST, 0);
  
  $query = "UPDATE smslist_list SET active=? WHERE id=?";
	
  $fields = null;
	
  if ($disable) {
	  $fields = array(0,$disable);
  }
  else if ($enable) {
	  $fields = array(1,$enable);
  }
	
  if (!is_null($fields)) {
	  $db->prepareAndExecuteQuery($query, $fields);
  }
  
  $query = null;
  
  $user = extractNumberWithKeyFromArray("user", $_REQUEST, null);
  
  if ($user) {
	  $smsUserListTableWriter->resetCustomIterator(" WHERE userid='".$user."'");
	  $query = " WHERE id IN (";
	  $started = false;
	  
	  while ($row = $smsUserListTableWriter->nextItem()) {
		  
		  if ($started) {
			  $query .= ", ";
		  }
		  
		  $query .= $row->listid;
		  $started = true;
	  }
	  
	  $query .= ")";
	  
  }
	
  $query .= " ORDER BY name";
  $smsListTableWriter->resetCustomIterator($query);
  if ($smsListTableWriter->db->numRows() > 0) {
	  while ($row = $smsListTableWriter->nextItem()) {
		  if (checkSMSListPermissions($db, $row->id, $authInfo->uid)) {
				$enableUrl = "/cms/html/index.php?fileNo=1&formid=".SMS_LIST_FORM;
				$enableUrl .= "&sorts=clear&direction=clear";
				if ($row->active) {
					$enableUrl .= "&disable=".$row->id;			
				}
				else {
					$enableUrl .= "&enable=".$row->id;
				}
	?>
		<tr> 
			<td colspan="6" >
				<img height="7" src="/cms/images/greyline.gif"  width="100%" />
			</td>
		</tr>
		<tr>
			<td>
				<?= $row->name ?>
			</td>
			<td >
	<?
		$q = "SELECT count(*) AS count FROM smslist_listuser WHERE listid=?";
		$fields = array( $row->id );
		if ($db->prepareAndExecuteQuery($q, $fields ) && $db->numRows() == 1){
			$count = ($db->nextObject());
			if ($count)
				echo $count->count;
	}
	?>
			</td>
			<td style="text-align: center;">
	<?
					$activeImage = $row->active == '1' ? 'active' : 'inactive';
					print <<< EOD
					<a href="$enableUrl"><img src="/cms/images/cnt_$activeImage.gif" width="10" height="10"></a>
						  
EOD;
	?>
			</td>
			<td >
				<a href="/cms/html/index.php?fileNo=1&formid=<?= SMS_LIST_USER_FORM; ?>&list=<?= $row->id; ?>&sorts=clear&direction=clear" >View</a> /
				<a href="/cms/html/index.php?fileNo=<?= SMS_MULTI_USER_ADD; ?>&list=<?= $row->id; ?>">Add </a> /
				<a href="/cms/html/index.php?fileNo=<?= SMS_MULTI_USER_REMOVE; ?>&list=<?= $row->id; ?>">Remove </a> /
				<a href="/cms/html/index.php?fileNo=<?= SMS_USER_REMOVE; ?>&listId=<?= $row->id; ?>">Remove All </a>
			</td>
			<td><a href="/cms/html/index.php?fileNo=<?= SMS_LIST_ADD; ?>&id=<?= $row->id; ?>">Edit</a>
			</td>		
		</tr>
	
	<?
			}
		}
	}
?>
	<tr> 
		<td colspan="6" > 
			<img height="7" src="/cms/images/greyline.gif"  width="100%" />
		</td>
	</tr>
    
</table>